<?php

namespace app\service;

use app\model\AdminAgent;
use think\facade\Session;

class AgentService
{
    /**
     * 获取合作商信息
     */
    public static function getAgentInfo(int $admin_id = 0)
    {
        try {
            $url = request()->url();
            if (str_contains($url, 'adminsystem.php')) {
                $prefix = 'admin_';
            } else {
                $prefix = 'agent_';
            }
            $user     = Session::get('admin_user_auth', $prefix);
            $admin_id = $user['uid'] ?: $admin_id;
            return AdminAgent::where('admin_id', $admin_id)->find()->toArray();
        } catch (\Throwable $e) {
            throw new \Exception('账号数据异常，请重新登录！');
        }
    }
}
